/**
 * Created by zhangguijie on 2017/5/12.
 */
$(function(){
    var $searchBar = $('#searchBar'),
        $searchResult = $('#searchResult'),
        $searchText = $('#searchText'),
        $searchInput = $('#searchInput'),
        $searchClear = $('#searchClear'),
        $searchCancel = $('#searchCancel');

    function hideSearchResult(){
        $searchResult.hide();
        $searchInput.val('');
    }
    function cancelSearch(){
        hideSearchResult();
        $searchBar.removeClass('weui-search-bar_focusing');
        $searchText.show();
    }

    $searchText.on('click', function(){
        $searchBar.addClass('weui-search-bar_focusing');
        $searchInput.focus();
    });
    $searchInput
        .on('blur', function () {
            if(!this.value.length) cancelSearch();
        })
        .on('input', function(){
            if(this.value.length) {
                $searchResult.show();
            } else {
                $searchResult.hide();
            }
        })
    ;
    $searchClear.on('click', function(){
        hideSearchResult();
        $searchInput.focus();
    });
    $searchCancel.on('click', function(){
        cancelSearch();
        $searchInput.blur();
    });
    $('.itemSpan').on('click',function () {
        $(this).addClass('selectColor');
        $(this).siblings().removeClass('selectColor');
        console.log($(this).html())
    });
    /*动态计算宽度*/
    var width = 70;
    var width2 = 50;
     $('.itemStyle').each(function (index,item) {
         width += item.clientWidth;
     });
    $('.itemSpan_color').each(function (index,item) {
        width2 += item.clientWidth;
    });
    setTimeout(function () {
       if(width>0) {
           $('.scroll_div').css('width',width)
       }
        if(width2>0) {
            $('.scroll_div2').css('width',width2)
        }
    },30);

    ///模糊查询
    $('.form').submit(function (event) {
        event.preventDefault();
        console.log( $searchInput.val());
        cancelSearch();
    });
    $('.preject_item_right').on('click',function () {
        window.location.href = 'itemDetails.html'
    });
    /* 首页跳转  需要判断*/
    $('.my_mry').on('click',function () {
        window.history.go(-1);
    });
    $('.geren_zx').on('click',function () {
        window.location.href = 'http://localhost:63342/shiyu-weixin/html/personalCenter/personalCenter.html'
    })
});